<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>取得结果集中行的数目</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysql-num-rows" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">mysql_num_rows</h1>
    <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mysql_num_rows</span> &mdash; <span class="dc-title">取得结果集中行的数目</span></p>

   </div>
   <div class="refsect1 unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-seealta" id="refsect1-function.mysql-num-rows-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-unknown-seealta">
    <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>mysql_num_rows</strong></span>
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$result</code></span>
      ) : <span class="type">int</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>mysql_num_rows()</strong></span>
     返回结果集中行的数目。此命令仅对
     SELECT 语句有效。要取得被
     INSERT，UPDATE 或者
     DELETE 查询所影响到的行的数目，用
     <span class="function"><a href="mysql_affected_rows.html" class="function">mysql_affected_rows()</a></span>。
     <div class="example" id="example-2160">
      <p><strong>Example #1 <span class="function"><strong>mysql_num_rows()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_user"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"mysql_password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">"database"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;table1"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$num_rows&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$num_rows</span><span style="color: #DD0000">&nbsp;Rows\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

     </div>
    </p>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
     <p class="para">
      如果使用
      <span class="function"><a href="mysql_unbuffered_query.html" class="function">mysql_unbuffered_query()</a></span>，则直到结果集中的所有行都被提取后
      <span class="function"><strong>mysql_num_rows()</strong></span>
      才能返回正确的值。
     </p>
    </p></blockquote>
    <p class="para">
     参见
     <span class="function"><a href="mysql_affected_rows.html" class="function">mysql_affected_rows()</a></span>，<span class="function"><a href="mysql_connect.html" class="function">mysql_connect()</a></span>，<span class="function"><a href="mysql_data_seek.html" class="function">mysql_data_seek()</a></span>，<span class="function"><a href="mysql_select_db.html" class="function">mysql_select_db()</a></span> 和
     <span class="function"><a href="mysql_query.html" class="function">mysql_query()</a></span>。
    </p>
    <p class="para">
     为向下兼容仍然可以使用
     <span class="function"><strong>mysql_numrows()</strong></span>，但反对这样做。
    </p>
   </div>

  </div></div></div></body></html>